package com.learn.service.impl;

import com.learn.dao.AccountDao;
import com.learn.pojo.Account;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/01/21
 * @description 全xml开发的业务类
 */
@Service
public class AllXmlService {
    @Resource
    private AccountDao accountDao;
    public void transfer(int fromId, int toId, double money) {
        Account from = accountDao.selectById(fromId);
        Account to = accountDao.selectById(toId);
        if (from.getBalance() < money) {
            throw new RuntimeException("余额不足");
        }
        from.setBalance(from.getBalance() - money);
        to.setBalance(to.getBalance() + money);

        int count = accountDao.updateBalance(from);
        String s = null;
        s.toString();
        count += accountDao.updateBalance(to);
        if (count != 2) {
            throw new RuntimeException("系统异常");
        }
    }
}
